﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Annotations;
using SharedGenomics.Workbench.Annotations;

namespace SharedGenomics.Workbench.Tests.Annotations
{
    [TestClass]
    public class ActiveAnnotationsPersistenceManagerTests
    {
        [TestMethod]
        public void ShouldLoad()
        {
            TestActiveAnnotationsPersistenceManager pm = new TestActiveAnnotationsPersistenceManager();
            pm.TestAnnotationDescriptors = new[]
            {
                AnnotationDescriptor.GetDescriptorForKey(AnnotationKey.GoogleSearch),
                AnnotationDescriptor.GetDescriptorForKey(AnnotationKey.NcbiSummary)
            };

            pm.ActiveAnnotationTypes = new[] { typeof(GoogleSearchAnnotation) };

            var descriptors = pm.Load().ToList();
            Assert.AreEqual(2, descriptors.Count);

            CollectionAssert.AreEquivalent(new[] { typeof(GoogleSearchAnnotation), typeof(NcbiAnnotation) }, descriptors.Select(kvp => kvp.Key.AnnotationType).ToArray());
            CollectionAssert.AreEquivalent(new[] { true, false }, descriptors.Select(kvp => kvp.Value).ToArray());
        }
    }

    #region TestActiveAnnotationsPersistenceManager

    public class TestActiveAnnotationsPersistenceManager : ActiveAnnotationsPersistanceManager
    {
        public IEnumerable<Type> ActiveAnnotationTypes { get; set; }
        public IEnumerable<AnnotationDescriptor> TestAnnotationDescriptors { get; set; }

        protected override IEnumerable<Type> GetActiveAnnotationTypes(IEnumerable<Type> availableAnnotationTypes)
        {
            return this.ActiveAnnotationTypes;
        }

        protected override IEnumerable<AnnotationDescriptor> AnnotationDescriptors
        {
            get { return this.TestAnnotationDescriptors; }
        }
    }

    #endregion
}
